package com.itheima.demo01;

import java.util.TreeSet;

public class Demo {

    public static void main(String[] args) {

        Student s1 = new Student("god",39);
        Student s2 = new Student("sad",33);
        Student s3 = new Student("bad",41);
        Student s4 = new Student("gold",39);

        /*TreeSet<Student> treeSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {

                int i = o1.getAge() - o2.getAge();

                int i1 = i == 0 ? o1.getName().compareTo(o2.getName()) : i;

                return i1;
            }
        });*/

        TreeSet<Student> treeSet = new TreeSet<>(((o1, o2) -> {

            int i = o1.getAge() - o2.getAge();

            int i1 = i == 0 ? o1.getName().compareTo(o2.getName()) : i;

            return i1;
        }));



        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.add(s4);

        for(Student a : treeSet){
            System.out.println(a.getName()+"----"+a.getAge());
        }
    }
}
